<template>
	<div class="headerbox">
		<div class="header">
			<div class="headerL">
				<a @click="goBack" class="goback"><img src="@/assets/picture/goback.png" /></a>
			</div>
			<div class="headerC">
				<p>我的订单</p>
			</div>
			<div class="headerR"></div>
		</div>
	</div>
	<div class="hbox"></div>
	<div class="myddcon">
		<div class="myddcon1" v-for="(order, index) in orderList" :key="index">
			<div class="shopbox" v-for="(ordergood, index2) in order.order_goods" :key="index2">
				<div class="shopboxL">
					<img src="@/assets/picture/22.png" />
				</div>
				<div class="shopboxR">
					<div class="shopboxR_1">
						<div class="sbr1_1">{{ordergood.product_name}}</div>
						<div class="sbr1_2">
							<p class="p2">￥{{ordergood.price}}</p>
						</div>
					</div>
					<div class="shopboxR_2">
						<p class="p4">×{{ordergood.num}}</p>
					</div>
				</div>
			</div>
			<div class="dphjbox">
				<p class="p5"><span class="order-date">{{ order.created_at }}</span>共 {{ order.order_goods.length }} 件商品，合计:<span>￥{{order.money}}</span></p>
			</div>
		</div>
	</div>
	<div class="fbox3"></div>
	<Footer />
	<div v-if="tip" class="tip-layer">
		<div class="tip">{{tipContent}}</div>
	</div>
</template>

<script>
	import axios from 'axios';
	import {
		showTips
	} from '@/assets/js/common.js';
	import Footer from '@/components/footer/index.vue'
	export default {
		name: 'allDd',
		components: {
			Footer
		},
		props: {
			msg: String
		},
		data() {
			return {
				httpUrl: 'http://qgm1.fengjian123.com/service9501/',
				tipContent: '',
				tip: 0,
				orderList: [],
			};
		},
		mounted() {
			this.isLogin();
		},
		methods: {
			isLogin() {
				const sessionData = window.sessionStorage.getItem('users');
				if (sessionData == null) {
					this.$router.push('/login');
					console.log("登录失效");
					return;
				}

				const userData = JSON.parse(sessionData);
				this.nickname = userData.nickname;

				axios.post(this.httpUrl + 'order/orderList', null, {
						headers: {
							'Authorization': 'Bearer ' + userData.token,
							'Content-Type': 'application/json',
						},
						params: {
							userId: userData.id,
						}
					})
					.then(res => {
						if (res.data.err == 0) {
							this.orderList = res.data.orderList;
						} else {
							console.log(res.data.msg);
							showTips(this, res.data.msg);
						}
					})
					.catch(error => {
						console.error("登录失败，请检查网络", error);
						showTips(this, '登录失败，请检查网络');
						this.$router.push('/login');
						return;
					});
			},
			goBack() {
				this.$router.go(-1);
			},
		},
	}
</script>

<style>
	@import url('@/assets/css/style.css');
</style>